﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnvDTE80;

namespace SPVisualDev.VSAddin.Dialogs
{
    public partial class DialogDebugTransportSelector : Form
    {
        private DTE2 m_dte2;

        public DialogDebugTransportSelector(DTE2 Dte2)
        {
            InitializeComponent();

            m_dte2 = Dte2;


            if (string.IsNullOrEmpty(Common.GetUserRegistryParam("DefaultDebugTransport", true)))
            {
                FillTransportsList("Default");
            }
            else
            {
                FillTransportsList(Common.GetUserRegistryParam("DefaultDebugTransport", true));
            }
        }

        private void FillTransportsList(string DefaultValue)
        {
            Debugger2 dbg2 = m_dte2.Debugger as Debugger2;

            this.cboTransports.Sorted = true;

            foreach (Transport transport in dbg2.Transports)
            {
                this.cboTransports.Items.Add(transport.Name);
            }

            for (int i = 0; i < this.cboTransports.Items.Count; i++)
            {
                if (this.cboTransports.Items[i].ToString().Equals(DefaultValue, StringComparison.OrdinalIgnoreCase))
                    this.cboTransports.SelectedIndex = i;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                Common.SetUserRegistryParam("DefaultDebugTransport", this.cboTransports.SelectedItem.ToString());

                this.DialogResult = DialogResult.OK;
                this.Hide();
            }
            catch(Exception ex)
            {
                DialogError.ShowError(ex);
            }
        }
    }
}
